package cn.kennylee.codehub.springmvc.appfilters.config;

import cn.kennylee.codehub.springmvc.appfilters.filter.UrlDecodeFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;

/**
 * <p> SpringMVC过滤器自动配置类 </p>
 * <p>Created on 2025/7/25.</p>
 *
 * @author kennylee
 * @since 0.0.1
 */
@AutoConfiguration
@Slf4j
public class WebFilterAutoConfiguration {
    /**
     * URL解码
     *
     * @return UrlDecodeAdvice
     */
    @Bean
    @ConditionalOnMissingBean
    public FilterRegistrationBean<UrlDecodeFilter> urlDecodeFilter() {
        FilterRegistrationBean<UrlDecodeFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new UrlDecodeFilter());
        registration.addUrlPatterns("/*");
        registration.setOrder(1);
        log.info("URL解码过滤器已加载");
        return registration;
    }

}
